package com.smec.remes.module.submit.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.smec.moblie.BR;
import com.smec.moblie.R;
import com.smec.moblie.databinding.LayoutRecyclerviewOtherBinding;
import com.smec.remes.base.SmecBaseRecyclerViewHolder;
import com.smec.remes.bean.DispalyAll;
import com.smec.remes.bean.SubmitConfirmeChildren;
import com.smec.remes.bean.SubmitDetailsConfirme;
import com.smec.remes.util.CommonUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/20.
 */

public class SmecWeiChildrenAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder>{

    private Context mcontext;
    private HashMap<Integer,Boolean> hashMap=new HashMap<>();
    private ArrayList<SubmitDetailsConfirme> submitDetailsConfirmeArrayList=new ArrayList<>();
    public void setArrayList( ArrayList<SubmitDetailsConfirme> list){
        submitDetailsConfirmeArrayList=list;
        notifyDataSetChanged();
    }

    public ArrayList<SubmitDetailsConfirme> getList(){
        return submitDetailsConfirmeArrayList;
    }



    public SmecWeiChildrenAdapter(Context context) {
        this.mcontext=context;
    }

    public void clear(){
        submitDetailsConfirmeArrayList.clear();
        notifyDataSetChanged();
    }


    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutRecyclerviewOtherBinding layoutRecyclerviewOtherBinding=DataBindingUtil.inflate
                (LayoutInflater.from(parent.getContext()), R.layout.layout_recyclerview_other,parent,false);
        SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new
                SmecBaseRecyclerViewHolder(layoutRecyclerviewOtherBinding.getRoot());
        smecBaseRecyclerViewHolder.setViewType(viewType);
        smecBaseRecyclerViewHolder.setBinding(layoutRecyclerviewOtherBinding);
        return smecBaseRecyclerViewHolder;
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, final int position) {
        final LayoutRecyclerviewOtherBinding layoutRecyclerviewOtherBinding= (LayoutRecyclerviewOtherBinding) holder.getBinding();
        layoutRecyclerviewOtherBinding.setVariable(BR.meihuo,submitDetailsConfirmeArrayList.get(position));
        if(submitDetailsConfirmeArrayList.get(position).getBackStatus()!=null && submitDetailsConfirmeArrayList.get(position).getBackStatus().equals("CANCELED")){
            layoutRecyclerviewOtherBinding.tvRetun.setVisibility(View.VISIBLE);
            layoutRecyclerviewOtherBinding.llOne.setBackground(mcontext.getResources().getDrawable(R.drawable.search_stokre_yellow));
        }
        if(hashMap.get(submitDetailsConfirmeArrayList.get(position).getDistributeId())!=null){
            boolean isSelected=hashMap.get(submitDetailsConfirmeArrayList.get(position).getDistributeId());
            layoutRecyclerviewOtherBinding.tvChoiceYes.setVisibility(isSelected ? View.VISIBLE :View.GONE);
            holder.getBinding().executePendingBindings();
        }
        checkTime(position,layoutRecyclerviewOtherBinding);
    }



    /**
     * 检查时间
     * @param position
     * @param layoutRecyclerviewOtherBinding
     */
    private void checkTime(int position,LayoutRecyclerviewOtherBinding layoutRecyclerviewOtherBinding){
        if(submitDetailsConfirmeArrayList.get(position).getFlag()!=null  && submitDetailsConfirmeArrayList.get(position).getFlag().equals("F")){
            layoutRecyclerviewOtherBinding.llShouhuoTime.setVisibility(View.VISIBLE);
        }else {
            layoutRecyclerviewOtherBinding.llShouhuoTime.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return submitDetailsConfirmeArrayList.size();
    }
}
